const { query } = require("../db/query")
module.exports = {
  // 获取宠物详情数据
  getPetDetails: async (pet_id) => {
    // 调用query发送sql语句到mysql进行注册用户
    return await query("SELECT petinformation.*,`user`.user_name FROM `user`,petinformation WHERE petinformation.pet_id = ? AND petinformation.user_id = `user`.user_id;", [pet_id])
  },
  // 查询宠物信息表中是否有该用户且pet_id对应
  isPet: async (user_id, pet_id) => {
    // 调用query发送sql语句到mysql进行注册用户
    return await query("select * from petinformation where user_id = ? and pet_id = ?", [user_id, pet_id])
  },
  // 修改积分
  editIntegral: async (user_id, collection_status) => {
    // 如果为true积分+1
    if (collection_status == "true") {
      // 调用query发送sql语句到mysql进行注册用户
      return await query("update user set user_integral = user_integral + 1 where user_id = ?", [user_id])
    }
    // 如果为false积分-1
    if (collection_status == "false") {
      // 调用query发送sql语句到mysql进行注册用户
      return await query("update user set user_integral = user_integral - 1 where user_id = ?", [user_id])
    }
  },
  // 判断是否在收藏表中
  isCollection: async (user_id, pet_id) => {
    // 调用query发送sql语句到mysql进行注册用户
    return await query("select * from mycollection where user_id = ? and pet_id = ?", [user_id, pet_id])
  },
  // 收藏宠物
  petCollection: async (user_id, pet_id, collection_status) => {
    // 调用query发送sql语句到mysql进行注册用户
    return await query("insert into mycollection(user_id, pet_id, collection_status) values(?,?,?)", [user_id, pet_id, collection_status])
  },
  // 修改收藏状态
  updateCollectionStatus: async (user_id, pet_id, collection_status) => {
    // 调用query发送sql语句到mysql进行注册用户
    return await query("update mycollection set collection_status = ? where user_id = ? and pet_id = ?", [collection_status, user_id, pet_id])
  }
}